package net.maku.events.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.events.vo.UserApplyCommentVO;
import net.maku.framework.common.utils.Result;
import net.maku.events.service.UserSnapshotService;
import net.maku.events.vo.UserSnapshotVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户随手拍作品
 *
 * @author 阿沐 babamu@126.com
 * @since 1.0.0 2025-03-22
 */
@RestController
@RequestMapping("events/user_snapshot")
@Tag(name = "用户随手拍作品")
@AllArgsConstructor
public class UserSnapshotController {
    private final UserSnapshotService userSnapshotService;

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('events:user_snapshot:info')")
    public Result<UserSnapshotVO> get(@PathVariable("id") Long id) {
        return Result.ok(userSnapshotService.getInfoById(id));
    }

    @DeleteMapping
    @Operation(summary = "删除")
    @PreAuthorize("hasAuthority('events:user_snapshot:delete')")
    public Result<String> delete(@RequestBody List<Long> idList) {
        userSnapshotService.delete(idList);

        return Result.ok();
    }

    @GetMapping("/give/or/cancel/{snapshotId}")
    @Operation(summary = "随手拍点赞或取消")
    public Result<String> giveOrCancel(@PathVariable("snapshotId") Long snapshotId) {
        userSnapshotService.giveOrCancel(snapshotId);
        return Result.ok();
    }

    @PostMapping("/apply/comment")
    @Operation(summary = "发布评价")
    public Result<String> applyComment(@RequestBody UserApplyCommentVO applyCommentVO) {
        userSnapshotService.applyComment(applyCommentVO);
        return Result.ok();
    }

    @GetMapping("/remove/comment/{commentId}")
    @Operation(summary = "删除评论")
    public Result<String> removeComment(@PathVariable("commentId") Long commentId) {
        userSnapshotService.removeComment(commentId);
        return Result.ok();
    }

    @GetMapping("/give/or/cancel/comment/{commentId}")
    @Operation(summary = "评论点赞或取消")
    public Result<String> giveOrCancelComment(@PathVariable("commentId") Long commentId) {
        userSnapshotService.giveOrCancelComment(commentId);
        return Result.ok();
    }

}